package ar.com.personalTravellers.generators;

import java.io.Serializable;
import java.util.Collection;

import ar.com.personalTravellers.beans.SGUser;

import com.angel.architecture.daos.RoleDAO;
import com.angel.architecture.daos.factory.ArchitectureDAOFactory;
import com.angel.architecture.flex.locator.ObjectLocator;
import com.angel.architecture.persistence.beans.Role;
import com.angel.architecture.persistence.beans.User;
import com.angel.dao.generic.factory.DAOFactory;
import com.angel.dao.generic.interfaces.GenericDAO;
import com.angel.data.generator.interfaces.DataGenerator;

/**
 *
 * @author William
 */
public class UserDataGenerator implements DataGenerator {

    private static final String ADMIN_ROLE_NAME= "Admin";
    private static final String GUEST_ROLE_NAME= "Guest";

	private static final long serialVersionUID = 1570123667875640283L;

	@SuppressWarnings("unchecked")
	public Class<? extends DataGenerator>[] getDependecesGenerators() {
        return (Class<? extends DataGenerator>[]) new Class[]{
                RoleDataGenerator.class
        };
    }

    public void generateData(Collection<Object> objects, DAOFactory daoFactory) {
    	RoleDAO roleDAO = ObjectLocator.getBeanByName("roleDAO");
        Role admin = roleDAO.findUniqueByName(ADMIN_ROLE_NAME);
        Role guest = roleDAO.findUniqueByName(GUEST_ROLE_NAME);

        SGUser gsalazar = new SGUser();
        gsalazar.setEmail("guillesalazar@gmail.com");
        gsalazar.setName("Guillermo Daniel");
        gsalazar.setPassword("123");
        gsalazar.addRole(admin);
        gsalazar.addRole(guest);
        objects.add(gsalazar);

        SGUser gaston = new SGUser();
        gaston.addRole(guest);
        gaston.setEmail("gaston@gmail.com");
        gaston.setName("Gaston");
        gaston.setPassword("123");
        objects.add(gaston);

        SGUser silvia = new SGUser();
        silvia.setEmail("silvia@gmail.com");
        silvia.setName("Silvia");
        silvia.setPassword("123");
        silvia.addRole(guest);
        objects.add(silvia);
    }

    public Class<? extends Object> getDataGeneratorClass() {
        return User.class;
    }

    @SuppressWarnings("unchecked")
	public GenericDAO<Object, Serializable> getGenericDAO() {
        return (GenericDAO<Object, Serializable>) ObjectLocator.getBeanByName("userDAO");
    }

	public Class<?> thisDataGeneratorClass() {
		return this.getClass();
	}
}
